package com.his.service.impl;

import com.his.entity.CaseHistory;
import com.his.entity.Patient;
import com.his.entity.Registration;
import com.his.entity.ResponseResult;
import com.his.mapper.CaseHistoryMapper;
import com.his.mapper.DiagnosisMapper;
import com.his.mapper.PatientMapper;
import com.his.mapper.RegistrationMapper;
import com.his.service.IRegistrationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 就诊(门诊)信息表（一个病人一个病历号，多次就诊，多次就诊信息），也可以看作医院的挂号表\n挂了号相当于开了一 服务实现类
 * </p>
 *
 * @author Demoon Liu
 * @since 2022-02-20
 */
@Service
public class RegistrationServiceImpl extends ServiceImpl<RegistrationMapper, Registration> implements IRegistrationService {

    @Resource
    public PatientMapper patientMapper;

    @Resource
    public RegistrationMapper registrationMapper;

    @Resource
    public CaseHistoryMapper caseHistoryMapper;

    @Override
    public ResponseResult regisPeo(Patient patient) {
        int code;
        String message;

        if(patientMapper.insert(patient)>0) {
            message = "插入成功";
            code = 201;
        }
        else {
            message = "插入失败";
            code = 400;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("patient", patient);

        return new ResponseResult(code, message,map);
    }

    @Override
    public ResponseResult regisHis(CaseHistory caseHistory) {
        int code;
        String message;

        if(caseHistoryMapper.insert(caseHistory)>0) {
            message = "插入成功";
            code = 201;
        }
        else {
            message = "插入失败";
            code = 400;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("caseHistory", caseHistory);

        return new ResponseResult(code, message,map);
    }


    @Override
    public ResponseResult regis(Registration registration) {
        int code;
        String message;
        registration.setEndattendance(1);

        if(registrationMapper.insert(registration)>0) {
            message = "插入成功";
            code = 201;
        }
        else {
            message = "插入失败";
            code = 400;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("registration", registration);

        return new ResponseResult(code, message,map);
    }

    
}
